package com.innovation.chengzhangriji.ui.widget;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.innovation.chengzhangriji.DiscoverPhoto;
import com.innovation.chengzhangriji.R;
import com.innovation.chengzhangriji.http.BabyResponse;
import com.innovation.chengzhangriji.ui.DiscoverGalleryActivity;

import java.util.ArrayList;

public class BabyDetailAdapter extends RecyclerView.Adapter<BabyDetailHolder> implements BabyDetailHolder.OnClickViewBigListener {

    private ArrayList<String> list_head;
    private int mSelect;
    private boolean[] mSelects;
    private int sex;

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    @Override
    public BabyDetailHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_babydetail, parent, false);
        BabyDetailHolder viewHolder = new BabyDetailHolder(view);
        viewHolder.setOnClickViewBigListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(BabyDetailHolder holder, int position) {
        holder.setHead(list_head.get(position), sex);
//        holder.setSelectVisibility(mSelects[position]);
    }

    @Override
    public int getItemCount() {
        if (list_head == null || list_head.size() == 0) {
            return 0;
        }
        return list_head.size();
    }

    public ArrayList<String> getList() {
        return list_head;
    }

    public void setList(ArrayList<String> list) {
        list_head = list;
        if(list_head.size() > 0) {
            mSelects = new boolean[list_head.size()];
            mSelects[0] = true;
        }
    }

    @Override
    public void onClickViewBig(BabyDetailHolder holder) {
        Intent intent = new Intent(holder.itemView.getContext(), DiscoverGalleryActivity.class);
        intent.putExtra("index", holder.getLayoutPosition());
        String[] photoUrls = new String[list_head.size()];
        intent.putExtra("photoUrls", list_head.toArray(photoUrls));
        holder.itemView.getContext().startActivity(intent);
//        for (int i = 0; i < mSelects.length; i++) {
//            if (mSelects[i]) {
//                mSelects[i] = false;
//                notifyItemChanged(i);
//                break;
//            }
//        }
//        mSelect = holder.getLayoutPosition();
//        mSelects[mSelect] = true;
//        notifyItemChanged(mSelect);
    }

}
